// request.js
import baseUrl from '@/config/api.js'
const request = (url, method = 'GET', data = {}, header = {}) => {
	return new Promise((resolve, reject) => {
		header["Authorization"] = uni.getStorageSync('token')
		// header["Authorization"] = 'b73b26354b31f1a620d21c5ce4ecb671XvUpZCzI4I'
		uni.showLoading({
			title: '加载中',
			mask: true
		})
		uni.request({
			url: baseUrl + url,
			method: method,
			data: data,
			header: header,
			success: (res) => {
				uni.hideLoading()
				if (res.data.code == 401) {
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}
				resolve(res.data)
			},
			fail: (err) => {
				uni.hideLoading()
				let result = {
					code: 500,
					msg: "获取数据失败"
				};
				reject(result)
			}
		})
	})
}
const get = (url, param) => {
	return request(url, "get", param, {
		'Content-Type': 'application/json'
	})
}
const post = (url, data) => {
	return request(url, "post", data, {
		'Content-Type': 'application/json'
	})
}
const deleteRequest = (url, data) => {
	return request(url, "delete", data, {
		'Content-Type': 'application/json'
	})
}
export const qzApi = {
	//登录
	login: async (data) => {
		return await post('/hm/login', data)
	},
	//地址相关
	//我的地址列表
	addressList: async () => {
		return await get('/hm/user/address/list')
	},
	//所有城市
	cityAll: async () => {
		return await get('/hm/user/address/city/all')
	},
	//POST 修改、新增地址
	addAddress: async (data) => {
		return await post('/hm/user/address/modify', data)
	},
	// GET 地址详情
	getAddressDetail: async (id) => {
		return await get('/hm/user/address/' + id)
	},
	// DELETE 删除地址
	deleteAddress: async (id) => {
		return await deleteRequest('/hm/user/address/' + id)
	},

	// 药品管理
	// 商品列表
	productList: async (data) => {
		return await post('/hm/product/page', data)
	},
	// 商品详情
	productDetails: async (id) => {
		return await get('/hm/product/info/' + id)
	},
	// POST 查询门店信息
	getShopList: async (data) => {
		return await post('/hm/pharmacy/list', data)
	},
	// POST 通过处方ID查询门店信息
	getShopListWithPrescriptionId: async (data) => {
		return await get('/hm/pharmacy/getPharmacyDesc/' + data)
	},

	// 购物车管理
	// POST 加入购物车
	addToCart: async (data) => {
		return await post('/hm/cart/addGoods', data)
	},
	// // GET 获取购物车中商品数量
	getQuantityInCart: async () => {
		return await get('/hm/cart/itemQuantity')
	},
	// POST 查询购物车
	getGoodsInCart: async (data) => {
		return await post('/hm/cart/query', data)
	},
	// POST 通过处方ID查询门店信息
	deleteGoodsInCart: async (data) => {
		return await post('/hm/cart/deleteProduct', data)
	},

	// POST 获取问诊列表
	getConsultationList: async (data) => {
		return await post('/hm/prescribePrescription/onLine/list', data)
	},
	// POST 申请咨询单
	applyAdvisory: async (data) => {
		return await post('/hm/prescribePrescription/onLine/applyAdvisory', data)
	},

	// 处方管理
	// GET 获取处方列表
	getPrescriptionList: async () => {
		return await get('/hm/rx/list')
	},
	// GET 获取处方详情
	getPrescriptionDetail: async () => {
		return await get('/hm/rx/detail')
	},
	// POST 将已上传的病历信息传给后端
	uploadMedicalRecordInfo: async (data) => {
		return await post('/hm/rx/oss/upload/complete', data)
	},


	// 订单管理
	// POST 确认订单
	confirmOrder: async (data) => {
		return await post('/hm/order/confirmOrder', data)
	},
	//POST 取消订单
	cancelOrder: async (data) => {
		return await post('/hm/order/orderCancel', data)
	},
	//POST 查询订单详情
	getOrderDetail: async (data) => {
		return await post('/hm/order/orderDetails', data)
	},
	//POST 查询订单列表
	getOrderList: async (data) => {
		return await post('/hm/order/pageQuery', data)
	},
	//GET 生成复昱订单
	getFyOrderSn: async () => {
		return await get('/hm/order/getTrade')
	},
	//POST 创建订单
	createOrder: async (data) => {
		return await post('/hm/order/submitOrder', data)
	},
	//GET 计算运费
	getFreight: async (id, id1) => {
		return await get('/hm/order/getFreight/' + id + '/' + id1)
	},
	// POST 支付
	payOrder: async (data) => {
		return await post('/hm/order/pay', data)
	},

	// 物流管理
	// GET 获取物流信息
	getLogisticsInfo: async (data) => {
		return await get('/hm/logisticsRouteOrder/logisticsRouteDetails/' + data)
	},


	// GET 获取OSS验证信息
	getOSSSigned: async (data) => {
		return await get('/hm/file/getSigned', data)
	},
	// GET 获取某个订单中已上传但未提交审核的病历
	getFileOfOrder: async (id) => {
		return await get('/hm/file/process/' + id)
	},
	// GET 上传病历后的提交审核
	confirmUploadFile: async (id,type) => {
		return await get('/hm/file/confirm/' + type+'/'+id)
	},
	// POST 上传的图片与订单绑定
	fileBindOrder: async (data) => {
		return await get('/hm/file/bindOrder', data)
	},
	// DELETE 删除已上传的图片
	deleteFile: async (id) => {
		return await deleteRequest('/hm/file/' + id)
	},

	// GET 获取OSS验证信息
	applyAdvisoryRequest: async (data) => {
		return await post('/hm/prescribePrescription/onLine/applyAdvisory', data)
	},

	getDrugList: async (data) => {
		return await post('/hm/product/page', data)
	},
	confirmOtc: async (data) => {
		return await get('/hm/order/confirmOtc/' + data)
	},
	pastCaseInfo: async (data) => {
		return await get('/hm/user/pastCaseInfo/')
	},
	
	addOrSubGoods: async (data) => {
		return await post('/hm/cart/addOrSubGoods', data)
	},

	creditDeduction: async (data) => {
		return await post('/hm/order/creditDeduction', data)
	},
}